<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">

	function doSave() 
	{
		if($("#code").val() == '') {
			alert("공통코드를 입력해 주세요.");
			return false;
		}
		if($("#name").val() == '') {
			alert("공통코드명을 입력해 주세요.");
			return false;
		}
		
		var params = {
			categoryCd: $("#code").val(),
		};
		
		$.get("/manage/category/check", params, function(result) {
			var status = JSON.parse(result).status;
			if(status == 0) {
				if(confirm("저장하시겠습니까?")) {
					var category = $('#category').serialize();
					
					$.post("/manage/category/write", category, function(result) {
						var status = JSON.parse(result).status;
						
						if(status != 0) {
							alert("정상적으로 저장되었습니다.");
							opener.location.replace('/manage/category');
							window.close();
						} else {
							alert("오류가 발생하였습니다.");
						}
					});
				}
			} else {
				alert("이미 존재하는 공통코드 입니다.");
			}
		});
		
		return false;
	}
</script>
</head>

<body>
<div class="content_top">
	<p class="path">
		<strong>공통코드</strong>
	</p>
</div>
<h4>서비스 별 공지사항이 보여지며, 등록, 수정 가능합니다.</h4>

<form:form modelAttribute="category" action="/manage/category/write" method="post">
<input type="hidden" id="regist" name="regist" value="${category.regist}">
<div class="tbl_type3">
	<table cellspacing="0" border="1">
	<col width="120">
	<col>
	<tr>
		<th>공통코드</th>
		<td>
			<input id="code" name="code" type="text" class="input_txt" style="width: 100%">
		</td>
	</tr>
	<tr>
		<th>사용여부</th>
		<td>
			<input type="radio" class="rdo" name="use" value="Y" checked="checked"><span>사용</span></input>  
			<input type="radio" class="rdo" name="use" value="N"><span>미사용</span></input>
		</td>
	</tr>
	<tr>
		<th>공통코드명</th>
		<td>
			<input id="name" name="name" type="text" class="input_txt" style="width: 100%">
		</td>
	</tr>
	<tr>
		<th>비고</th>
		<td>
			<textarea id="desc" name="desc" class="input_txt" style="width: 100%; height: 150px;" rows="10" cols="10"></textarea>
		</td>
	</tr>
	</table>
</div>
<br>

<div class="div_right">
	<a href="javascript:;" class="btn_big" onclick="doSave();"><strong>저장</strong></a>
	<a href="javascript:;" class="btn_big" onclick="parent.close();"><strong>닫기</strong></a>
</div>
</form:form>
</body>
</html>